
//
//	cove.geom.Matrix - 2011 July 5th
//
//	The Matrix class represents a transformation matrix that determines how to map points from one
//	coordinate space to another.
//
//	>> concat() provides a different answer to the one in AS3 sometimes
//
//-------------------------------------------------------------------------------------------------

var Matrix = cove.geom.Matrix = Class.extend({
	
	init: function(a, b, c, d, tx, ty) {
		this.a = isNaN(a) ? 1 : a;
		this.b = isNaN(b) ? 0 : b;
		this.c = isNaN(c) ? 0 : c;
		this.d = isNaN(d) ? 1 : d;
		this.tx = isNaN(tx) ? 0 : tx;
		this.ty = isNaN(ty) ? 0 : ty;
	},


//	Public methods
//-------------------------------------------------------------------------------------------------
	
	// Returns a new Matrix object that is an exact copy of this matrix.
	clone: function() {
		return new Matrix(this.a, this.b, this.c, this.d, this.tx, this.ty);
	},
	
	// Concatenates a matrix with the current matrix, effectively combining the geometric effects of the two.
	concat: function(matrix) {
		var a = this.a, c = this.c, tx = this.tx,
			b = this.b, d = this.d, ty = this.ty;
		this.a = a * matrix.a + c * matrix.b;
		this.b = b * matrix.a + d * matrix.b;
		this.c = a * matrix.c + c * matrix.d;
		this.d = b * matrix.c + d * matrix.d;
		this.tx = tx * matrix.a + ty * matrix.b + matrix.tx;
		this.ty = tx * matrix.c + ty * matrix.d + matrix.ty;
	},
	
	// Includes parameters for scaling, rotation, and translation.		
	createBox: function(scaleX, scaleY, rotation, tx, ty) {
		if(isNaN(rotation)) rotation = 0;
		if(isNaN(tx)) tx = 0;
		if(isNaN(ty)) ty = 0;
		//void
	},
	
	// Creates the specific style of matrix expected by the beginGradientFill() and lineGradientStyle() methods of the Graphics class.
	createGradientBox: function(width, height, rotation, tx, ty) {
		if(isNaN(rotation)) rotation = 0;
		if(isNaN(tx)) tx = 0;
		if(isNaN(ty)) ty = 0;
		//void
	},
	
	// Given a point in the pretransform coordinate space, returns the coordinates of that point after the transformation occurs.	
	deltaTransformPoint: function(point) {
		//Point
	},
	
	// Sets each matrix property to a value that causes a null transformation.
	identity: function() {
		//void
	},
	
	// Performs the opposite transformation of the original matrix.
	invert: function() {
		//void
	},
	
	// Applies a rotation transformation to the Matrix object.
	rotate: function(angle) {
		var cos = Math.cos(angle),
			sin = Math.sin(angle);
		this.concat(new Matrix(cos, sin, -sin, cos));
	},
	
	// Applies a scaling transformation to the matrix.
	scale: function(sx, sy) {
		this.concat(new Matrix(sx, 0, 0, sy));
	},
	
	// Returns a text value listing the properties of the Matrix object.
	toString: function() {
		return (
			'(a=' + this.a +
			', b=' + this.b +
			', c=' + this.c +
			', d=' + this.d +
			', tx=' + this.tx +
			', ty=' + this.ty +
			')'
		);
	},
	
	// Returns the result of applying the geometric transformation represented by the Matrix object to the specified point.
	transformPoint: function(point) {
		//Point
	},
	
	// Translates the matrix along the x and y axes, as specified by the dx and dy parameters.
	translate: function(dx, dy) {
		this.concat(new Matrix(1, 0, 0, 1, dx, dy));
	}

});
